import { defineStore } from 'pinia'
import { getInfo } from '@/api/login'
import { useMenuStore } from './menu'
export const useUserStore = defineStore('userId', {
    state: () => {
        return {
            permissions: [],
            userInfo: {},
            roles: [],
            rolePerm: ''
        }
    },
    actions: {
        async getUserInfo() {
            const res = await getInfo()
            this.userInfo = res.data.userInfo;
            this.rolePerm = res.data.roles[0].rolePerm;
            this.permissions = res.data.permissions
            this.roles = res.data.roles
            useMenuStore().getMenu(this.rolePerm);
        }
    },
    persist: {
        enabled: true,
        strategies: [{
            storage: localStorage,
        }]
    },
})